import logging
import multiprocessing
from worker import Worker
from camera import CameraManager
from detector_hand import HandGestureDetector
from detector_head import HeadGestureDetector
from detector_face import FacialExpressionDetector
from detector_speech import SpeechCommandDetector
from dispatcher import Dispatcher

logging.basicConfig(level=logging.INFO)


if __name__ == '__main__':
    buffer_commands = multiprocessing.SimpleQueue()
    buffer_webcam_for_hand = multiprocessing.SimpleQueue()
    buffer_webcam_for_head = multiprocessing.SimpleQueue()
    buffer_webcam_for_face = multiprocessing.SimpleQueue()
    workers: list[Worker] = [
        CameraManager(
            (buffer_webcam_for_hand,
             buffer_webcam_for_head,
             buffer_webcam_for_face)
        ),
        HandGestureDetector(buffer_commands, buffer_webcam_for_hand),
        HeadGestureDetector(buffer_commands, buffer_webcam_for_head),
        FacialExpressionDetector(buffer_commands, buffer_webcam_for_face),
        SpeechCommandDetector(buffer_commands),
        Dispatcher(buffer_commands)
    ]
    worker_processes = [
        multiprocessing.Process(target=worker.run_forever)
        for worker in workers
    ]
    for thread in worker_processes:
        thread.start()
    for thread in worker_processes:
        thread.join()
